package br.imr.dao.impl;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

import br.imr.model.Membro;

/**
 *
 */
public class HibernateUtil {

	private static SessionFactory sessionFactory;

	private HibernateUtil() {}

	/**
	 * 
	 */
	public static SessionFactory getSessionFactory() {
		if(sessionFactory == null){
			try{
				// Cria o SessionFactory from standard (hibernate.cfg.xml)
				// config file.
				AnnotationConfiguration ac = new AnnotationConfiguration();
				ac.addAnnotatedClass(Membro.class);
				sessionFactory = ac.configure().buildSessionFactory();
			}catch (Throwable ex){
				// Log do exception.
				System.err.println("Initial SessionFactory creation failed." + ex);
				throw new ExceptionInInitializerError(ex);
			}
			return sessionFactory;
		}else{
			return sessionFactory;
		}
	}
	
}
